package com.chujian.framework.ws.support.cli;

import com.alibaba.fastjson.JSON;
import com.chujian.framework.ws.WsMsg;
import com.chujian.framework.ws.IWsSendExecutor;
import lombok.extern.slf4j.Slf4j;

/**
 * 客户端 -> 服务端的发送执行器
 */
@Slf4j
public class WsCliSendExecutor implements IWsSendExecutor {

    private final WsCli wsCli;

    public WsCliSendExecutor(WsCli wsCli) {
        this.wsCli = wsCli;
    }

    @Override
    public void send(WsMsg msg) throws Exception {
        String msgStr = JSON.toJSONString(msg);

        log.debug("客户端发送消息：{}", msgStr);

        wsCli.send(msgStr);
    }
}
